# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm/configs/lineageos_i9305_defconfig

pkgname=linux-samsung-i9300
pkgver=3.0.101
pkgrel=2
pkgdesc="Samsung Galaxy SIII kernel fork"
arch="armv7"
_carch="arm"
_flavor="samsung-i9300"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="bash bc bison devicepkg-dev flex openssl-dev perl xz gcc6"

# Compiler: this kernel was only tested with GCC6. Feel free to make a merge
# request if you find out that it is booting working with newer GCCs as
# well. See <https://postmarketos.org/vendorkernel> for instructions.
if [ "${CC:0:5}" != "gcc6-" ]; then
	CC="gcc6-$CC"
	HOSTCC="gcc6-gcc"
	CROSS_COMPILE="gcc6-$CROSS_COMPILE"
fi

# Source
_repository="android_kernel_samsung_smdk4412"
_commit="fa8fa332fdec11744ffe0c742775cc22efe0d041"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::https://github.com/LineageOS/$_repository/archive/$_commit.tar.gz
	$_config
"
builddir="$srcdir/$_repository-$_commit"
_outdir="out"

prepare() {
	default_prepare
	. downstreamkernel_prepare
}

build() {
	unset LDFLAGS
	make O="$_outdir" ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"

	# the 'no-pic' flag is necessary to avoid the
	# error 'Unknown symbol _GLOBAL_OFFSET_TABLE_ (err 0)' when loading the module
	make O="$_outdir" ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS" \
		CFLAGS_MODULE="-fno-pic" modules
}

package() {
	downstreamkernel_package "$builddir" "$pkgdir" "$_carch" "$_flavor" "$_outdir"

	unset LDFLAGS
	make O="$_outdir" ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS" \
		INSTALL_MOD_PATH="$pkgdir" INSTALL_MOD_STRIP=1 modules_install
}

sha512sums="d87dd54152980b30012fead62e639dde6ff0862d376790eac32800aeffd91482a220c7b1f233933a1879796dcaa3722e86c42a5f0e4df4168ae1f65362952779  linux-samsung-i9300-fa8fa332fdec11744ffe0c742775cc22efe0d041.tar.gz
c1c667ff55603101ae0bb3cfb085a0536a4e817ee9e116b62bead734f758099b1abcbe21c2d8e4790de2a62bd48e3b60ae8e0eb529b829ad71e2ddf1e0296b8d  config-samsung-i9300.armv7"
